package com.wu.leetcode.leetcode387;

/**
 * Leetcode387-字符串中的第一个唯一字符
 * <p>
 * s = "leetcode"
 * 返回 0
 * s = "loveleetcode"
 * 返回 2
 */
class Solution {
    public int firstUniqChar(String s) {
        int length = s.length();
        if (s == null || length == 0) {
            return -1;
        }
        int[] nums = new int[26];
        for (int i = 0; i < length; i++) {
            nums[s.charAt(i) - 'a']++;
        }
        for (int i = 0; i < length; i++) {
            if (nums[s.charAt(i) - 'a'] == 1){
                return i;
            }
        }
        return -1;
    }
}